<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客注册页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">

</head>

<body>
    <div class="nav">
        <img src="pic/boke.jpg" alt="">
        <span class="blog-title">知行笔记</span>
        <div class="space"></div>
    </div>

    <div class="container-login">
        <div class="login-dialog">
            <h3>注册</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" name="username" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password" id="password">
            </div>
            <div class="row">
                <button id="submit2" onclick="register()">注册</button>
            </div>
            <div class="row">
                <button id="submit1" onclick="login()">已有账号，去登录</button>
            </div>

        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        function login(){
            location.href = 'blog_login.html';
        }
        function register() {
            $.ajax({
                type: "post",
                url: "user/register",
                data: {
                    "userName": $("#username").val(),
                    "password": $("#password").val()
                },
                success:function(result){
                    if(result.code == 200 && result.code != null){
                        alert("注册成功！")
                        location.href = "blog_login.html"
                    }else if(result.errMsg == "1"){
                        alert("用户名和密码不能为空！");
                    }else if(result.errMsg == "2"){
                        alert("用户已存在，请换一个用户名注册！");
                    }else if(result.errMsg == "3"){
                        alert("用户名的长度在2~13之间！");
                    }else if(result.errMsg == "4"){
                        alert("请将密码的长度设置在3~13个字符之间！");
                    }
                    //不为200如何处理.....
                }
            });
        }
    </script>
</body>

</html>